
export default {
	common: {
		baseUrl: "https://admin.dqzjw.cn/",
		method: "GET",
		// data是前端给后端传东西的地方
		data: {},
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		timeout: 5000
	},
	request(options = {}) {
		// 加载中提示框
		uni.showLoading({
			title: '加载中'
		});
		options.url = this.common.baseUrl + options.url;
		options.data = options.data || this.common.data;
		options.header = options.header || this.common.header;
		options.method = options.method || this.common.method;
		options.dataType = options.dataType || this.common.dataType;
		//判断是否传了token
		if (options.header.token) {
			options.header.token = store.state.user.token
			if (!store.state.user.token) {
				uni.showToast({
					title: "请先登入",
					icon: 'none'
				})
				return 
			}
		}

		return new Promise((res, rej) => {
			uni.request({
				...options,
				success: (result) => {
					// console.log(result.data.data,'66666')
					if (result.data.code !== 1) {
						return rej(result.data);
						uni.hideLoading();
					}
					let data = result.data;
					res(data);
					// 关闭加载中提示框
					setTimeout(function() {
						uni.hideLoading();
					}, 20);
				}
			})
		})
	},
}